﻿namespace Rage.Base
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;

    public partial class TextInputDialog : ChildWindow
    {
        public TextInputDialog(string title, string message, string initialValue, IEnumerable<string> forbiddenValues)
        {
            InitializeComponent();

            Title = title;
            ForbiddenValues = forbiddenValues;
            LB_Message.Text = InitialMessage = message;
            TB_Input.TextChanged += TB_Input_TextChanged;
            TB_Input.Text = initialValue;
        }

        private void TB_Input_TextChanged(object sender, TextChangedEventArgs e) {
            bool enable = true;
            if (string.IsNullOrEmpty(TB_Input.Text)) { enable = false; }
            if (enable && ForbiddenValues.Contains(TB_Input.Text)) { enable = false; }
            BT_OK.IsEnabled = enable;
        }

        private string InitialMessage;
        private IEnumerable<string> ForbiddenValues;
        public string Result { get { return this.TB_Input.Text; } set { this.TB_Input.Text = value; } }

        private void BT_OK_Click(object sender, RoutedEventArgs e) { DialogResult = true; }
        private void BT_Cancel_Click(object sender, RoutedEventArgs e) { DialogResult = false; }
    }
}
